package framework.editors
{

	public class EditorManager
	{
		public static var editors:Array = [ new DefaultEditor, new XMLEditor ];

		public function EditorManager()
		{
		}

		static public function registerEditor(editor:IEditor):void
		{
			editors.push(editor);
		}

		static public function getBestReader(obj:*, propName:Object):IEditor
		{
			return getBest(obj, propName, "canRead");
		}

		static public function getBestWriter(obj:*, propName:Object):IEditor
		{
			return getBest(obj, propName, "canWrite");
		}

		static private function getBest(obj:*, propName:Object, func:String):IEditor
		{
			var bestPriority:int = 0;
			var currentChoice:IEditor;
			for each (var ed:IEditor in editors)
			{
				var priority:int = ed[func](obj, propName);
				if (priority > bestPriority)
				{
					currentChoice = ed;
					bestPriority = priority;
				}
			}
			return currentChoice;
		}

	}
}